<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns="http://conqat.cs.tum.edu/ns/clonereport"
		   targetNamespace="http://conqat.cs.tum.edu/ns/clonereport"
		   xmlns:cr="http://conqat.cs.tum.edu/ns/clonereport"
		   xmlns:xs="http://www.w3.org/2001/XMLSchema"
		   elementFormDefault="qualified">

	<!-- Clone Report (Root) -->

	<xs:element name="cloneReport">
		<xs:annotation>
			<xs:documentation>
				The root element of a ConQAT clone report.
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="sourceFile" minOccurs="0" maxOccurs="unbounded" />
				<xs:element ref="cloneClass" minOccurs="0" maxOccurs="unbounded" />
			</xs:sequence>
			<xs:attribute name="systemdate" type="xs:string" use="optional" />
		</xs:complexType>

		<!-- Source File Contraints -->

		<xs:key name="sourceFileKey">
			<xs:annotation>
				<xs:documentation>
					This constraint ensures that every source file has a non-null id and that it is unique across the whole clone report.
				</xs:documentation>
			</xs:annotation>
			<xs:selector xpath="cr:sourceFile" />
			<xs:field xpath="@id" />
		</xs:key>

		<!-- Clone Class Constraints -->

		<xs:key name="cloneClassKey">
			<xs:annotation>
				<xs:documentation>
					This constraint ensures that every clone class has a non-null id and that it is unique across the whole clone report.
				</xs:documentation>
			</xs:annotation>
			<xs:selector xpath="cr:cloneClass" />
			<xs:field xpath="@id" />
		</xs:key>
		<xs:unique name="cloneClassUniqueId">
			<xs:annotation>
				<xs:documentation>
					This constraint ensures that the optional string-based unique id of a clone class is unique across the whole clone report.
				</xs:documentation>
			</xs:annotation>
			<xs:selector xpath="cr:cloneClass" />
			<xs:field xpath="@uniqueId" />
		</xs:unique>

		<!-- Clone Constraints -->

		<xs:unique name="cloneId">
			<xs:annotation>
				<xs:documentation>
					This constraint ensures that the optional id of a clone is unique across the whole clone report.
				</xs:documentation>
			</xs:annotation>
			<xs:selector xpath="cr:cloneClass/cr:clone" />
			<xs:field xpath="@id" />
		</xs:unique>
		<xs:unique name="cloneUniqueId">
			<xs:annotation>
				<xs:documentation>
					This constraint ensures that the optional string-based unique id of a clone is unique across the whole clone report.
				</xs:documentation>
			</xs:annotation>
			<xs:selector xpath="cr:cloneClass/cr:clone" />
			<xs:field xpath="@uniqueId" />
		</xs:unique>
		<xs:keyref name="cloneToSourceFile" refer="sourceFileKey">
			<xs:annotation>
				<xs:documentation>
					This constraint ensures that every clone has a valid reference to a source file.
				</xs:documentation>
			</xs:annotation>
			<xs:selector xpath="cr:cloneClass/cr:clone" />
			<xs:field xpath="@sourceFileId" />
		</xs:keyref>
	</xs:element>

	<!-- Source File -->

	<xs:element name="sourceFile">
		<xs:annotation>
			<xs:documentation>
				Describes a source file that was analyzed by clone detective. This also includes
				files for which no clone was found.
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:attribute name="id" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a unique id of the source file. Used by a clone element to reference the source file.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="path" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the fully qualified path of the file. The exact syntax is depending on the platform clone detective
						has been executed on.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="length" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the number of lines (i.e. lines of code, LOC) of the source file.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="fingerprint" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains an MD5 hash of the source file's content.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>

	<!-- Clone Class -->

	<xs:element name="cloneClass">
		<xs:annotation>
			<xs:documentation>
				Describes a clone class found by clone detective. A clone class represents a piece of code that is duplicated.
				A clone on the other hand represents such a duplicate. Therefore a clone class contains all its clones.
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="values" minOccurs="0" />
				<xs:element ref="clone" minOccurs="0" maxOccurs="unbounded" />
			</xs:sequence>
			<xs:attribute name="id" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a unique id for this clone class.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="uniqueId" type="xs:string" use="optional"/>
			<xs:attribute name="fingerprint" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a string of arbitrary length that identifies this clone class across clone reports. It
						is used for blacklisting. Furthermore, it is evaluated when programmatically determining equality
						of clone classes, i.e. it needs to be present and no two clone classes in a report should have the
						same fingerprint.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="normalizedLength" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the length of the clones in this clone class measured in units. Depending on the normalization
						technique units can be words, lines, tokens or statements.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>

	<!-- Clone -->

	<xs:element name="clone">
		<xs:annotation>
			<xs:documentation>
				Represents a region of duplicated source code.
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="values" minOccurs="0" />
			</xs:sequence>
			<xs:attribute name="id" type="xs:int" use="optional"/>
			<xs:attribute name="uniqueId" type="xs:string" use="optional"/>
			<xs:attribute name="sourceFileId" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the id the source file the clone is contained in.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="startLine" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the zero-based line number this clone starts.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="lineCount" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the number of line of this clone.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="startUnitIndexInFile" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the index of the first unit of this clone. Depending on the normalization
						technique units can be words, lines, tokens or statements.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="lengthInUnits" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the number of units this clone comprises. Depending on the normalization
						technique units can be words, lines, tokens or statements.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="deltaInUnits" type="xs:int" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains the edit distance in units from this clone to the clone class representative.
						For ungapped clone classes, this value is always zero.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="gaps" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a string that describes the gap positions. For ungapped clone classes, this value
						is always the empty string.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="fingerprint" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a string of arbitrary length that identifies this clone class across clone reports. It
						is used for blacklisting. Furthermore, it is evaluated when programmatically determining equality
						of clone classes, i.e. it needs to be present and no two clone classes in a report should have the
						same fingerprint. For ungapped clone classes, all clones contained in the clone class share the same
						fingerprint.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>

	<!-- Values -->

	<xs:element name="values">
		<xs:annotation>
			<xs:documentation>
				Contains a list of key value pairs associated with the clone
				class.
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="value" minOccurs="0" maxOccurs="unbounded" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<!-- Value -->

	<xs:element name="value">
		<xs:annotation>
			<xs:documentation>
				Represents a key value pair associated with a clone class.
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:attribute name="key" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a unique key to identify a value associated with a clone class.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="value" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a value associated with a clone class.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="type" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						Contains a type description of the value.
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>

</xs:schema>
